package org.example.system.dubbo;

import com.alibaba.excel.util.ListUtils;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.example.api.system.RemoteMassageService;
import org.example.api.system.domain.bo.RemoteMassageBo;
import org.example.common.websocket.utils.WebSocketUtils;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
@DubboService
@RequiredArgsConstructor
public class RemoteMassageServiceImpl implements RemoteMassageService {
    @Override
    public void sendMessage(Long sessionKey, String message) {
        this.sendMessage(ListUtils.newArrayList(sessionKey),message);
    }

    @Override
    public void sendMessage(Long sessionKey, RemoteMassageBo message) {
        this.sendMessage(sessionKey, JSON.toJSONString(message));
    }

    @Override
    public void sendMessage(List<Long> sessionKey, String message) {
        sessionKey.forEach(key-> WebSocketUtils.sendMessage(key,message));
    }

    @Override
    public void sendMessage(List<Long> sessionKey, RemoteMassageBo message) {
        this.sendMessage(sessionKey,JSON.toJSONString(message));
    }

    @Override
    public void sendGroupMessage(String group, String message) {
        WebSocketUtils.sendGroupMessage(group,message);
    }

    @Override
    public void sendGroupMessage(String group, RemoteMassageBo message) {
        this.sendGroupMessage(group,JSON.toJSONString(message));
    }

    @Override
    public void publishAll(String message) {
        WebSocketUtils.publishAll(message);
    }

    @Override
    public void publishAll(RemoteMassageBo message) {
        this.publishAll(JSON.toJSONString(message));
    }
}
